<#include "head_bus.ftl">
<script>
window.onload=function(){
	$("title").html("我的业务-登录密码修改");
}
</script>
<!--内容开始-->
<div class="container">
    <ol class="breadcrumb">
      <li><a href="#">首页</a></li>
      <li><a href="#">个人中心</a></li>
      <li class="active">登录密码修改</li>
    </ol>
    <div class="l-content f18">
       <a href="###" class="icon icon-7 i-radius" data-toggle="modal" data-target="#modal-13" data-backdrop="static" data-dismiss="modal"><span>手机找回</span></a>
       <a href="###" class="icon icon-8 i-radius" data-toggle="modal" data-target="#modal-4" data-backdrop="static" data-dismiss="modal"><span>邮箱找回</span></a>
       <a href="###" class="icon i-edit i-radius" data-toggle="modal" data-target="#modal-10" data-backdrop="static" data-dismiss="modal"><span>原密码修改</span></a>
    </div>
 
</div>
<!-- 弹出层 -->
<!-- 手机找回 -->
<div class="modal fade" id="modal-13">
    <div class="modal-dialog">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" href="javascript:cancle('modal-13')">×</a>   
               <h4><span>手机找回</span></h4>
           </div>
           <div class="modal-body text-center way">
                <form class="form-horizontal f14" method="post">
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">手  机  号：</label>
                      <div class="col-sm-7  col-xs-8">
                         <input type="text" class="form-control" id="account">
                      </div>
                   </div>
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">验  证  码：</label>
                      <div class="col-sm-7  col-xs-8">
                         <input type="text" class="form-control fl int-code " id="verify">
                         <a href="javascript:checking()" id="getVerify" class="btn btn-y code code-5 fr">获取验证码</a>
                         <a href="###" class="btn btn-c code-1 fr d-none" id="reGetVerify">重新发送</a>
                      </div>

                   </div>
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">新登录密码：</label>
                      <div class="col-sm-7  col-xs-8">
                         <input type="password" class="form-control" id="newpass" maxlength="16">
                      </div>
                   </div>
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">确认登录密码：</label>
                      <div class="col-sm-7  col-xs-8">
                         <input type="password" class="form-control" id="repass" maxlength="16">
                      </div>
                   </div>  
                    <div class="form-group">
                      <div class="text-center">
                          <button type="button" class="btn btn-s btn-120" onclick="resetPassByPhone()">确认</button>
                          <button type="button" class="btn btn-s btn-120 btn-cyan ml80" onclick="cancle('modal-13')">取消</button>
                      </div>
                  </div>                                
                </form>
           </div>
        </div>
    </div>
</div>
<!-- 手机找回成功 -->
<div class="modal fade" id="modal-3">
    <div class="modal-dialog modal-400">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" data-dismiss="modal">×</a>   
           </div>
           <div class="modal-body text-center">
                <span class="glyphicon glyphicon-ok ok"></span><br/>
                <p class="h4 mt20">登录密码修改成功</p>
           </div>
        </div>
    </div>
</div>
<!-- 邮箱找回 -->
<div class="modal fade" id="modal-4">
    <div class="modal-dialog modal-516">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" href="javascript:cancle('modal-4')">×</a>   
               <h4><span>邮箱找回</span></h4>
           </div>
           <div class="modal-body text-center">
                <form action="#" method="post">
                    <p class="tips f13">输入绑定邮箱，发送验证邮件，您的绑定邮箱会接收到一封验证邮件，请在
24小时之内打开邮件内的验证链接完成支付密码修改业务。</p>
                    <div class="form-group">
                        <div class="col-xs-12 fn">
                            <div class="input-group">
                                <span class="input-group-addon input-left">账号绑定邮箱：</span>
                                <input type="text" class="form-control input-220" id="mailaddr">
                            </div>
                        </div>
                    </div>
                     <div class="form-group">
                        <div class="text-center">
                            <button type="button" class="btn btn-s btn-120" onclick="resetPassByMail()">发送</button>
                            <button type="button" class="btn btn-s btn-120 btn-cyan ml80" onclick="cancle('modal-4')">取消</button>
                        </div>
                    </div>               
                </form>
           </div>
        </div>
    </div>
</div>
<!-- 验证邮件成功 -->
<div class="modal fade" id="modal-5">
    <div class="modal-dialog modal-400">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" data-dismiss="modal">×</a>   
           </div>
           <div class="modal-body text-center">
                <span class="glyphicon glyphicon-ok ok"></span><br/>
                <p class="h4 mt20">验证邮件发送成功</p>
                <p class="f14 col9">请您于24小时内完成验证</p>
           </div>
        </div>
    </div>
</div>
<!-- 验证邮件失败 -->
<div class="modal fade" id="modal-6">
    <div class="modal-dialog modal-400">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" data-dismiss="modal">×</a>   
           </div>
           <div class="modal-body text-center">
                <span class="glyphicon glyphicon-remove remove"></span><br/>
                <p class="h4 mt20">验证邮件发送失败</p>
                <p class="f14 col9">请重新验证</p>
           </div>
        </div>
    </div>
</div>
<!-- 原密码修改 -->
<div class="modal fade" id="modal-10">
    <div class="modal-dialog">
        <div class="modal-content">
           <div class="modal-header">
               <a class="close" href="javascript:cancle('modal-10')">×</a>   
               <h4><span>原密码修改</span></h4>
           </div>
           <div class="modal-body text-center way">
                <form class="form-horizontal f15" method="post">
                  <!-- <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">登录账号：</label>
                      <div class="col-sm-7  col-xs-7">
                         <input type="text" class="form-control">
                      </div>
                   </div>-->
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">原  密  码：</label>
                      <div class="col-sm-7  col-xs-7">
                         <input type="password" class="form-control" id="oldpassword">
                      </div>
                   </div>
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">新  密  码：</label>
                      <div class="col-sm-7  col-xs-7">
                         <input type="password" class="form-control" id="newpassword" maxlength="16">
                      </div>
                   </div>  
                   <div class="form-group">
                      <label class="col-sm-4 col-xs-4 control-label">确认密码：</label>
                      <div class="col-sm-7  col-xs-7">
                         <input type="password" class="form-control" id="repassword" maxlength="16">
                      </div>
                   </div>                   
                    <div class="form-group">
                      <div class="text-center">
                          <button type="button" class="btn btn-s btn-120" onclick="updatePass()">修改</button>
                          <button type="button" class="btn btn-s btn-120 btn-cyan ml80" onclick="cancle('modal-10')">取消</button>
                      </div>
                  </div>                                
                </form>
           </div>
        </div>
    </div>
</div>
<script>
	/**发送验证码**/
		function checking(){
		    var account=$("#account").val();
		    //验证手机号
			var array=[[/^[1-9][\d]{10}?$/,account,"手机号不正确，请输入11位手机号"]];
			for(var	 i=0;i<array.length	;i++)
			{
				if(array[i][0].test(array[i][1])==false)
				{
					$("#getVerify").removeAttr("style");
		    		$("#reGetVerify").attr("style","display:none");
					alertMsgError("手机发送验证码失败",array[i][2]);
					return;
				}
			}
		    if(''==account){
		    	$("#getVerify").removeAttr("style");
		    	$("#reGetVerify").attr("style","display:none");
		    	alertMsgError("手机发送验证码失败","请先输入手机号码,在发送验证码");
		    	return;
		    }
		    
		    var timeSms = getCookieValue("secondsremained");
		    if(timeSms>0){
		    	alert(timeSms+"秒后，请重新获取验证码!");
		    	time('getVerify','reGetVerify');
		    	return;
		    }
		    $.ajax({
		            cache: true,
		            type: "POST",
		            url:"${BASE_PATH}/user/verifyyzm.json",
		            data:{account:account,status:2},
		            async: true,
		            success: function(data){
		               if(data.status==1){//发送成功
		               		//time('getVerify','reGetVerify');
		               		addCookie("secondsremained",60,60);//添加cookie记录,有效时间60s
				            alertMsgSuccess("手机发送验证码成功",data.info);
						}else if(data.status==2){//发送失败
							//time('getVerify','reGetVerify');
				            alertMsgError("手机发送验证码失败",data.info);
						}else{
							//time('getVerify','reGetVerify');
				            alertMsgError("手机发送验证码失败",data.info);
						}
						time('getVerify','reGetVerify');
		            }
		     });
		}

	//手机找回密码
	function resetPassByPhone(){
		var account=$("#account").val();
		var verify=$("#verify").val();
		var newpassword=$("#newpass").val();
		var repassword=$("#repass").val();
		if(''==account){
			alertMsgError("手机找回密码失败","手机号不能为空");
			return;
		}
		if(''==verify){
			alertMsgError("手机找回密码失败","验证码不能为空");
			return;
		}
		if(''==newpassword){
			alertMsgError("手机找回密码失败","新密码不能为空");
			return;
		}
		if(''==repassword){
			alertMsgError("手机找回密码失败","重复密码不能为空");
			return;
		}
		
		//验证手机号
		var array=[[/^[1-9][\d]{10}?$/,account,"联系电话格式不正确，请输入11位手机号"],[/^[0-9a-zA-Z]{6,16}?$/,newpassword,"登录密码格式不正确，请输入6-16位密码"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alertMsgError("手机找回密码失败",array[i][2]);
				return;
			}
		}
		
		$.ajax({
	            cache: true,
	            type: "POST",
	            url:"${BASE_PATH}/user/updatePassByPhone.json",
	            dataType : 'json',
	            data:{account:account,verify:verify,newpassword:newpassword,repassword:repassword},
	            async: false,
	            success: function(data){
	               if(data){
	               		if(data.status=='1'){
	               			alertMsgSuccess("手机找回密码成功",data.info);
	               			$('#modal-13').modal('hide');
	               			eachInputEmpty('modal-13');
	               		}else{
	               			alertMsgError("手机找回密码失败",data.info);
	               		}
	               }
	            }
	        });
	}
	
	//取消
	function cancle(modal){
		$("#"+modal+"").modal('hide');
		eachInputEmpty(modal);
		window.location.reload();
	}
	
	function cancleClose(modal){
		$("#"+modal+"").modal('hide');
		eachInputEmpty(modal);
	}
	
	//邮箱修改密码
	function resetPassByMail(){
		var mailaddr=$("#mailaddr").val();
		if(''==mailaddr){
			//alert("请填写绑定的邮箱");
			alertMsgError("验证邮件发送失败","请填写绑定的邮箱");
			return;
		}
		$.ajax({
	            cache: true,
	            type: "POST",
	            url:"${BASE_PATH}/user/returnPassByMail.json",
	            dataType : 'json',
	            data:{mailaddr:mailaddr},
	            async: false,
	            success: function(data){
	               if(data){
	               		if(2==data.status){
	               			alertMsgSuccess("验证邮件发送成功",data.info);
	               			$('#modal-4').modal('hide');
	               			eachInputEmpty('modal-4');
	               		}else{
	               			alertMsgError("验证邮件发送失败",data.info);
	               		}
	               }
	            }
	        });
	}
	
	
	//修改密码
	function updatePass(){
		var oldpassword=$("#oldpassword").val();
		var newpassword=$("#newpassword").val();
		var repassword=$("#repassword").val();
		if(''==oldpassword){
			alert("旧密码不能为空");
			return;
		}
		if(''==newpassword){
			alert("新密码不能为空");
			return;
		}
		if(''==repassword){
			alert("确认密码不能为空");
			return;
		}
		
		
		//验证
		var array=[[/^[0-9a-zA-Z]{6,16}?$/,newpassword,"登录密码格式不正确，请输入6-16位密码"]];
		for(var	 i=0;i<array.length	;i++)
		{
			if(array[i][0].test(array[i][1])==false)
			{
				alert(array[i][2]);
				return;
			}
		}
		
		$.ajax({
	            cache: true,
	            type: "POST",
	            url:"${BASE_PATH}/user/password.json",
	            dataType : 'json',
	            data:{oldpass:oldpassword,newpass:newpassword,newpass1:repassword},
	            async: false,
	            success: function(data){
	               if(data){
	               		if(1==data.status){
	               			alert(data.info);
	               			$('#modal-10').modal('hide');
	               			eachInputEmpty('modal-10');
	               		}else{
	               			alert(data.info);
	               		}
	               }
	            }
	        });
		
	}
	var t=3;
	//失败-错误,弹窗
	function alertMsgError(title,msg){
		$('#modal-6 p').each(function(index){
			if(index==0){
				$(this).html("<font>"+title+"</font>");
			}else{
				$(this).html("<font color=red>"+msg+"</font><br><font id='overTime'></font>");
			}
		})
		$('#modal-6').modal('show');
		overTime(t,'modal-6');
	}
	
	//倒计时
	function overTime(t,modal){
		var str="";
		if(t==0){
			cancleClose(modal);
		}else{
			str="本窗口将在"+t+"秒后自动关闭";
			t--;
			$("#overTime").text("("+str+")");
			setTimeout(function(){
				overTime(t,modal);
			},1000);
		}
	}
	//成功弹窗
	function alertMsgSuccess(title,msg){
		$('#modal-5 p').each(function(index){
			if(index==0){
				$(this).html("<font>"+title+"</font>");
			}else{
				$(this).html("<font>"+msg+"</font><br><font id='overTime'></font>");
			}
		})
		$('#modal-5').modal('show');
		overTime(t,'modal-5');
	}
	//清空input
	function eachInputEmpty(id){
		$("#"+id+" input").each(function(){
			$(this).val("");
		})
	}
</script>

<#include "foot_bus.ftl">